package com.kazimsoylu;

import java.util.HashMap;

import javax.swing.JOptionPane;

import com.kazimsoylu.gui.ConversationWindow;

import net.sf.jml.MsnContact;
import net.sf.jml.MsnMessenger;
import net.sf.jml.MsnSwitchboard;

public class Application 
{
	public static MsnMessenger messenger;
	public static HashMap<String,ConversationWindow> conversationList;
	public static HashMap<String, MsnSwitchboard> switchBoards;
	
	static
	{
		conversationList = new HashMap<String, ConversationWindow>();
		switchBoards = new HashMap<String, MsnSwitchboard>();
	}
	
	public static void addConversation( MsnContact contact, ConversationWindow conw )
	{
		conversationList.put( contact.getId() , conw );
	}
	
	public static void removeConversation( MsnContact contact )
	{
		try
		{
			conversationList.remove( contact.getId() );
		}
		catch( NullPointerException ex )
		{
			JOptionPane.showMessageDialog(null, ex.getMessage() );
		}
	}
	
	public static ConversationWindow getConversation( MsnContact contact )
	{
		if( conversationList.containsKey( contact.getId() ) )
			return conversationList.get( contact.getId() );
		
		return null;
	}
	
	public static void addSwitchBoard( MsnContact contact, MsnSwitchboard sw )
	{
		switchBoards.put( contact.getId() , sw);
	}
	
	public static void removeSwitchBoard( MsnContact contact )
	{
		try
		{
			switchBoards.remove( contact.getId() );
		}
		catch( NullPointerException ex )
		{
			JOptionPane.showMessageDialog(null, ex.getMessage() );
		}
	}
	
	public static MsnSwitchboard getSwitchBoard( MsnContact contact )
	{
		if( switchBoards.containsKey( contact.getId() ) )
			return switchBoards.get( contact.getId() );
		
		return null;
	}
}
